package com.wimcorp.magic.behaviour.attack;

import javax.persistence.Entity;

import com.wimcorp.magic.cards.Creature;
import com.wimcorp.magic.players.Player;

@Entity
public class FirstStrike extends AttackBehaviour {

	private static FirstStrike instance = new FirstStrike();

	protected FirstStrike() {

	}

	public FirstStrike(Creature creature, AttackBehaviour attackBehaviour) {
		super(creature, attackBehaviour);
	}

	public FirstStrike(Creature creature) {
		super(creature, null);
	}

	public static FirstStrike instance() {
		return instance;
	}

	protected void attack(Creature defender) {
		getAttackBehaviour().attack(defender);
		if (defender.hasBehaviour(FirstStrike.instance()) || defender.hasBehaviour(DoubleStrike.instance())
				|| defender.isAlive()) {
			defender.counter(getCreature());
		}
	}
	
	@Override
	public void counter(Creature attacker) {
		getAttackBehaviour().counter(attacker);
	}

	protected void attack(Player defender) {
		defender.subtractLife(getCreature().getActualPower());
		getCreature().setActualPower(0);
	}

	public int priority() {
		return AttackType.FIRST_STRIKE.ordinal();
	}

	public boolean equals(Object o) {
		return o instanceof FirstStrike;
	}
}
